<html>
<head>
    <meta charset="utf-8">
    <title>个人信息设置</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">

    <!-- <link rel="stylesheet" href="/css/theme5.css"> -->
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script src="/js/md5.js"></script>

</head>
<body style="background-color: #fff">


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend>个人信息设置</legend>
                    </fieldset>
                </div>

                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">用户信息</li>
                        <li>修改密码</li>
                    </ul>
                    <div class="layui-tab-content" style="height: 100px;">

                        <div class="layui-tab-item  layui-show">
                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="userInfoForm">
                                    <input type="hidden" name="id" id="id" value="${user.id!}">
                                    <input type="hidden" name="roleId" id="roleId" value="${user.roleId!}">


                                    <div class="layui-form-item">
                                        <label class="layui-form-label">账户</label>
                                        <div class="layui-input-inline">
                                            <input type="text" disabled name="ename" id="ename" value="${user.ename!}"
                                                   class="layui-input">
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">昵称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入昵称" autocomplete="off" name="cname"
                                                       value="${user.cname!}"
                                                       id="cname"
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <label class="layui-form-label">手机号</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入手机号" autocomplete="off" id="mobile"
                                                       name="mobile" value="${user.mobile!}"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">邮箱</label>
                                            <div class="layui-input-inline">
                                                <input type="email" placeholder="请输入邮箱" autocomplete="off" name="email"
                                                       id="email" value="${user.email!}"
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <label class="layui-form-label">毕业学校</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入毕业学校" autocomplete="off" id="school"
                                                       name="school" value="${user.school!}"
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <label class="layui-form-label">学校链接</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入学校链接" autocomplete="off"
                                                       id="schoolLink" name="schoolLink" value="${user.schoolLink!}"
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <label class="layui-form-label">专业</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入专业" autocomplete="off"
                                                       id="profession" name="profession" value="${user.profession!}"
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <label class="layui-form-label">开始工作时间</label>
                                            <div class="layui-input-inline">
                                                <input name="beginJobTime" id="beginJobTime" placeholder="请输入开始工作时间"
                                                       value="${user.beginJobTime!}"
                                                       autocomplete="off" class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <label class="layui-form-label">结束工作时间</label>
                                            <div class="layui-input-inline">
                                                <input name="endJobTime" id="endJobTime" placeholder="请输入结束工作时间"
                                                       autocomplete="off" value="${user.endJobTime!}"
                                                       class="layui-input">
                                            </div>
                                        </div>


                                        <div class="layui-inline">
                                            <label class="layui-form-label">微信</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入微信" autocomplete="off" id="wechat"
                                                       name="wechat" value="${user.wechat!}"
                                                       class="layui-input">
                                            </div>
                                        </div>


                                        <div class="layui-inline">
                                            <label class="layui-form-label">微博</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入微博" autocomplete="off" id="weibo"
                                                       name="weibo" value="${user.weibo!}"
                                                       class="layui-input">
                                            </div>
                                        </div>


                                        <div class="layui-inline">
                                            <label class="layui-form-label">QQ</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入QQ" autocomplete="off" id="qq"
                                                       name="qq" value="${user.qq!}"
                                                       class="layui-input">
                                            </div>
                                        </div>


                                        <div class="layui-inline">
                                            <label class="layui-form-label">Twitter</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入Twitter" autocomplete="off"
                                                       id="twitter" name="twitter" value="${user.twitter!}"
                                                       class="layui-input">
                                            </div>
                                        </div>


                                        <div class="layui-inline">
                                            <label class="layui-form-label">Facebook</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入Facebook" autocomplete="off"
                                                       id="facebook" name="facebook" value="${user.facebook!}"
                                                       class="layui-input">
                                            </div>
                                        </div>


                                    </div>
                                    <div class="layui-form-item">
                                        <button type="button" class="layui-btn layui-btn-normal" lay-submit
                                                lay-filter="saveUserInfo">保存
                                        </button>
                                    </div>

                                </form>
                            </div>
                        </div>


                        <div class="layui-tab-item">

                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="updPwdForm">
                                    <input type="hidden" name="id" id="id" value="${user.id}">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">账户</label>
                                        <div class="layui-input-inline">
                                            <input type="text" disabled name="ename" id="ename"
                                                   value="${user.ename}"
                                                   class="layui-input">
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <label class="layui-form-label">原密码</label>
                                        <div class="layui-input-inline">
                                            <input type="password" name="oldPassword" id="oldPassword"
                                                   placeholder="请输入原密码" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">新密码</label>
                                            <div class="layui-input-inline">
                                                <input type="password" name="newPassword" id="newPassword"
                                                       placeholder="请输入新密码" autocomplete="off" class="layui-input">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">重新输入</label>
                                            <div class="layui-input-inline">
                                                <input type="password" name="againPassword" name="againPassword"
                                                       placeholder="请重新输入新密码" autocomplete="off"
                                                       class="layui-input">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">

                                        <div class="layui-inline">
                                            <label class="layui-form-label">验证码</label>
                                            <div class="layui-input-inline">
                                                <input type="text" placeholder="请输入验证码" autocomplete="off"
                                                       name="pwdVerCode" id="pwdVerCode"
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <img id="pwdCaptcha"
                                                 onclick="this.src = '/user/edit/image?m=' + Math.floor(Math.random() * 10000);"
                                                 src="/user/edit/image?m=" + Math.floor(Math.random() * 10000);>
                                        </div>


                                    </div>


                                    <div class="layui-form-item">
                                        <button type="button" class="layui-btn layui-btn-normal" lay-submit
                                                lay-filter="saveFieldShow">保存
                                        </button>
                                    </div>

                                </form>
                            </div>


                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;


        laydate.render({
            elem: '#beginJobTime' //指定元素
        });

        laydate.render({
            elem: '#endJobTime' //指定元素
        });

        //修改密码监听
        form.on('submit(saveFieldShow)', function (data) {

            if (!data.field.ename) {
                layer.msg("用户名不能为空", {
                    time: 2000
                });
                return;
            }

            if (!data.field.newPassword) {
                layer.msg("新密码不能为空", {
                    time: 2000
                });
                return;
            }

            if (!data.field.againPassword) {
                layer.msg("请重新输入新密码", {
                    time: 2000
                });
                return;
            }
            if (data.field.oldPassword) {
                data.field.oldPassword = hex_md5(data.field.oldPassword);
            }
            if (data.field.newPassword) {

                data.field.newPassword = hex_md5(data.field.newPassword);
            }
            if (data.field.againPassword) {
                data.field.againPassword = hex_md5(data.field.againPassword);
            }


            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/user/edit/password",
                data: JSON.stringify(data.field),
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }

                    $("#pwdVerCode").val('');
                    var pwdCaptcha = document.getElementById("pwdCaptcha");
                    pwdCaptcha.src = '/user/edit/image?m=' + Math.floor(Math.random() * 10000);
                },
                error: function (data) {
                    layer.msg(data.message);
                    $("#pwdVerCode").val('');
                    var pwdCaptcha = document.getElementById("pwdCaptcha");
                    pwdCaptcha.src = '/user/edit/image?m=' + Math.floor(Math.random() * 10000);
                }
            });
            return false;
        });


        //博主信息监听
        form.on('submit(saveUserInfo)', function (data) {

            if (!data.field.ename) {
                layer.msg("用户名不能为空", {
                    time: 2000
                });
                return;
            }

            if (!data.field.cname) {
                layer.msg("昵称不能为空", {
                    time: 2000
                });
                return;
            }

            if (!data.field.email) {
                layer.msg("邮箱不能为空", {
                    time: 2000
                });
                return;
            }
            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/user/addup",
                data: JSON.stringify(data.field),
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);

                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 2000);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });
            return false;
        });


    });
</script>


</body>
</html>